<template>
  <div class="app-container">
    <!--表格渲染-->
    <el-dialog
      :close-on-click-modal="false"
      :before-close="handleClose"
      :visible.sync="flag"
      title="AD配置信息维护"
      width="840px"
      @open="selAdInfo()"
    >
      <el-card class="box-card" :body-style="{ padding: '3px' }">
        <el-form label-width="140px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="AD服务器地址">
                <el-input v-model="addForm.adInfo.host" placeholder="请填写地址" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="AD服务器domain">
                <el-input v-model="addForm.adInfo.ldapDomain" placeholder="请填写domain" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="AD服务器用户">
                <el-input v-model="addForm.adInfo.userName" placeholder="请填写用户" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="AD服务器密码">
                <el-input v-model="addForm.adInfo.passWord" type="password" placeholder="请填写密码" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <!-- <el-col :span="12">
              <el-form-item label="证书路径">
                <el-input v-model="addForm.adInfo.cerPath" placeholder="请填写证书路径" />
              </el-form-item>
            </el-col> -->
            <el-col :span="12">
              <el-form-item label="关键字group">
                <el-input v-model="addForm.adInfo.objectClassG" placeholder="请填写关键字group" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="关键字user">
                <el-input v-model="addForm.adInfo.objectClassU" placeholder="请填写关键字user" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="gou">
                <el-input v-model="addForm.adInfo.gOu" placeholder="请填写gou" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="uou">
                <el-input v-model="addForm.adInfo.uOu" placeholder="请填写uou" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="uid、gid自增长值">
                <el-input v-model="addForm.adInfo.guId" placeholder="请填写uid、gid自增长值" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="新增用户默认密码">
                <el-input v-model="addForm.adInfo.userPwd" type="password" placeholder="请填写密码" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="gEnd">
                <el-input v-model="addForm.adInfo.gEnd" placeholder="请填写gEnd" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="loginShell">
                <el-input v-model="addForm.adInfo.loginShell" placeholder="请填写loginShell" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="文件路径">
                <el-input v-model="addForm.adInfo.unixHomeDirectory" placeholder="请填写文件路径" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClose">取消</el-button>
        <el-button type="primary" @click="saveAdInfo">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { saveAdInfo, selAdInfo } from '@/api/monitor/clusterWh'

export default {
  data() {
    return {
      addForm: {
        centerId: '1',
        url: '',
        cmFlag: '',
        cmName: '',
        adInfo: {
          host: '',
          ldapDomain: '',
          userName: '',
          passWord: '',
          cerPath: '/home/test_trus_store1',
          objectClassG: 'group',
          objectClassU: 'user',
          gOu: 'ou=groups,ou=stbase,dc=stbg,dc=com',
          uOu: 'ou=users,ou=stbase,dc=stbg,dc=com',
          guId: '2022080001',
          gEnd: 'grp',
          loginShell: '/bin/bash',
          unixHomeDirectory: '/user',
          userPwd: '123456'
        },
        initAdInfo: {
          host: '',
          ldapDomain: '',
          userName: '',
          passWord: '',
          cerPath: '/home/test_trus_store1',
          objectClassG: 'group',
          objectClassU: 'user',
          gOu: 'ou=groups,ou=stbase,dc=stbg,dc=com',
          uOu: 'ou=users,ou=stbase,dc=stbg,dc=com',
          guId: '2022080001',
          gEnd: 'grp',
          loginShell: '/bin/bash',
          unixHomeDirectory: '/user',
          userPwd: '123456'
        }
      },
      flag: false,
      radio: 'YARN',
      cmFlag: '',
      centerId: '',
      clusterFlag: '',
      type: 'YARN',
      clusterList: []
    }
  },
  created() {
    // 获取当前中心
    // this.selUserUnit()
  },
  methods: {
    handleClose() {
      this.flag=false
      this.addForm.initAdInfo={
        host: '',
        ldapDomain: '',
        userName: '',
        passWord: '',
        cerPath: '/home/test_trus_store1',
        objectClassG: 'group',
        objectClassU: 'user',
        gOu: 'ou=groups,ou=stbase,dc=stbg,dc=com',
        uOu: 'ou=users,ou=stbase,dc=stbg,dc=com',
        guId: '2022080001',
        gEnd: 'grp',
        loginShell: '/bin/bash',
        unixHomeDirectory: '/user',
        userPwd: '123456'
      }
    }, selAdInfo() {
      const params = {
        'centerId': this.centerId,
        'cmFlag': this.cmFlag
      }
      selAdInfo(params).then(res => {
        if (res != null && res.clusterId != null) {
          this.addForm.adInfo = res
        } else {
          this.addForm.adInfo = this.addForm.initAdInfo
        }
      }).catch(err => {
        if (err != null) {
          console.log(err.response.data.message)
        } else {
          console.log('请求失败!')
        }
      })
    }, saveAdInfo() {
      const reqData = {
        'centerId': this.centerId,
        'cmFlag': this.cmFlag,
        'adInfo': this.addForm.adInfo
      }
      saveAdInfo(reqData).then(res => {
        this.$notify.success({
          title: '成功',
          message: '提交成功！',
          duration: 15000
        })
        this.addForm.adInfo = this.addForm.initAdInfo
        this.flag = false
      }).catch(err => {
        this.$notify.error({
          title: '失败',
          message: '提交失败！',
          duration: 15000
        })
        if (err != null) {
          console.log(err.response.data.message)
        } else {
          console.log('请求失败!')
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
